package fr.afcepf.ai90.venteenligne.data;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.sql.DataSource;

import fr.afcepf.ai90.venteenligne.entity.Personne;
import fr.afcepf.ai90.venteenligne.util.SimpleDataSource;
/**
 * Classe DataPersonneImpl.
 * @author stagiaire
 *
 */
public class DataPersonneImpl implements IDataPersonne {

    @Override
    public Personne verifConnection(String paramMail, String paramMdp) {
        DataSource dc = new SimpleDataSource();
        Personne retour = null;
        try {
            Connection cnx = dc.getConnection();
            PreparedStatement pstmt = cnx.prepareStatement("SELECT * FROM Personne p WHERE p.mail = ? AND p.mdp = ?");
            pstmt.setString(1, paramMail);
            pstmt.setString(2, paramMdp);
            ResultSet rs = pstmt.executeQuery();
            if (rs.next()) {
                retour = new Personne(rs.getInt("id"),
                        rs.getString("nom"),
                        rs.getString("prenom"),
                        rs.getDate("date_naissance"),
                        rs.getString("mail"),
                        rs.getString("mdp"));
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return retour;
    }

}
